package br.com.medmark.model.hibernate.dao;

import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

import br.com.medmark.model.hibernate.Horario;
import br.com.medmark.model.hibernate.Usuario;

public class HorarioDAO extends GenericoDAOImpl<Horario>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4190461159319308107L;
	private static HorarioDAO horarioDAO = null;
	
	private HorarioDAO(){
		
	}
	
	public static HorarioDAO getInstance(){
		
		if ( horarioDAO == null) {
			horarioDAO = new HorarioDAO();
		}
	
		return horarioDAO;
		
	}
	
	public Horario getHorario(int codigo) {
		String sql = "FROM Horario h Where h.codigo = :codigo";
		
		TypedQuery<Horario> query = this.entityManager.createQuery(sql, Horario.class);
		query.setParameter("codigo", codigo);
	
		try {
			return query.getSingleResult();
		} catch (NoResultException ex) {
			return null;
		}
	}

}
